//
//  JMPresenrationController.swift
//  JMWB
//
//  Created by 个人电脑 on 16/3/16.
//  Copyright © 2016年 个人电脑. All rights reserved.
//

import UIKit

class JMPresenrationController: UIPresentationController {
    var presentedFrame : CGRect = CGRectZero
//蒙版懒加载
    private lazy var coverView : UIView = UIView()
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
//        presentedView()?.frame = CGRect(x: 100, y: 60, width: 180, height: 250)
   presentedView()?.frame = presentedFrame

       setupCoverView()
    }
}
extension JMPresenrationController{
//添加蒙版
    private func setupCoverView(){
    
        coverView.frame = containerView!.bounds
        //蒙版背景色
        coverView.backgroundColor = UIColor(white: 0.8, alpha: 0.2)
        //监听点击
        let tapGes = UITapGestureRecognizer(target: self, action: "coverViewClick")
        coverView.addGestureRecognizer(tapGes)
        //将蒙版添加到容器试图中
        containerView?.insertSubview(coverView, belowSubview: presentedView()!)
        
    }
    @objc private func coverViewClick(){
    presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
}
